package uz.edo.db.manager;

import uz.edo.db.bean.Department;
import uz.edo.db.bean.Organisation;
import uz.edo.db.manager.core.DBManager;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: said
 * Date: 1/14/12
 * Time: 2:21 AM
 * To change this template use File | Settings | File Templates.
 */
public class DepartmentManager extends DBManager {
    private static DepartmentManager instance = new DepartmentManager();

    public static DepartmentManager getInstance(){
        return instance;
    }

    public DepartmentManager() {
        super(Department.class);
    }

    public List<Department> getDepartments(Organisation organisation) throws Exception {
        return createQuery("from DepartmentListView d where d.organisation = :organisation")
                .setParameter("organisation", organisation)
                .list();
    }

    public Department getDepartment(String name) throws Exception {
        return (Department) createQuery("from DepartmentListView d where d.name = :name")
                .setParameter("name",name)
                .uniqueResult();
    }
}
